

Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Exceptions


Namespace SGW.ComunicadorWeb

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The ViewDynamicModule class displays the content
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public MustInherit Class Inicio
        Inherits Entities.Modules.PortalModuleBase
        Implements Entities.Modules.IActionable
        Dim PageIndex As Integer

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Try
                Dim objPortalSecurity As New PortalSecurity

                If Request.IsAuthenticated = False Then
                    If PortalSettings.LoginTabId <> -1 Then
                        'user defined tab
                        Response.Redirect(NavigateURL(PortalSettings.LoginTabId), True)
                    Else
                        'Admin Tab
                        Response.Redirect(NavigateURL("Login"), True)
                    End If
                End If

                ' If this is the first visit to the page, populate the site data
                If Page.IsPostBack = False Then

                    If Not Request.QueryString("CurrentPage") Is Nothing Then
                        PageIndex = CType(Request.QueryString("CurrentPage"), Integer)
                    Else
                        PageIndex = 1
                    End If

                    If Not Request.QueryString("PageRecords") Is Nothing Then
                        'ddlRecordsPerPage.SelectedValue = Request.QueryString("PageRecords")
                    End If

                    BindData()

                End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Private Sub BindData()

            Dim TotalRecords As Integer

            Dim PageSize As Integer = 10
            Dim CurrentPage As Integer = PageIndex

            Me.LabelBienvenido.Text = Replace(Localization.GetString("LabelBienvenido.Text", Me.LocalResourceFile), "[USERNAME]", Me.UserInfo.DisplayName)

            Dim objComunicadorWebs As New ComunicadorWebController
            Dim colActivos As List(Of ComunicadorWebInfo)
            Dim colCerrados As List(Of ComunicadorWebInfo)

            Dim objconfigs As New SGW_ConfiguracionController
            Dim GruposQuePuedenResponder As String = objconfigs.GetSGW_ConfiguracionBycfg_Descripcion(PortalId, "SGWComunicadorWeb_GruposQuePuedenResponder")

            If objconfigs.usuarioestaenunodelosgrupos(UserInfo, GruposQuePuedenResponder) Or UserInfo.IsInRole("Administrators") Then
                colActivos = objComunicadorWebs.GetAllComunicadorWebsActivos(PortalId)
                colCerrados = objComunicadorWebs.GetAllComunicadorWebsCerrados(PortalId, PageSize, CurrentPage - 1)
                TotalRecords = objComunicadorWebs.CountAllComunicadorWebsCerrados(PortalId)
            Else
                colActivos = objComunicadorWebs.GetComunicadorWebsActivos(PortalId, Me.UserInfo.UserID)
                colCerrados = objComunicadorWebs.GetComunicadorWebsCerrados(PortalId, Me.UserInfo.UserID, PageSize, CurrentPage - 1)
                TotalRecords = objComunicadorWebs.CountComunicadorWebsCerrados(PortalId, UserId)
                Me.lstContentActivos.Columns(2).Visible = False
                Me.lstContent.Columns(2).Visible = False
            End If

            If colActivos.Count > 0 Then
                lstContentActivos.DataSource = colActivos
                lstContentActivos.DataBind()
                'InitializePaging(PAGINGCONTROLAbiertos, TotalRecordsActivos, PageSize)
            Else
                lstContentActivos.Visible = False
                LabelNoActivos.Visible = True

                LabelNoActivos.Text = Localization.GetString("LabelNoActivos", Me.LocalResourceFile)
                'Me.PAGINGCONTROLAbiertos.Visible = False
            End If

            If colCerrados.Count > 0 Then
                lstContent.DataSource = colCerrados
                lstContent.DataBind()
                InitializePaging(PAGINGCONTROLCerrados, TotalRecords, PageSize)
            Else
                lstContent.Visible = False
                LabelNoCerrados.Visible = True
                LabelNoCerrados.Text = Localization.GetString("LabelNoCerrados", Me.LocalResourceFile)
                Me.PAGINGCONTROLCerrados.Visible = False
            End If

        End Sub
        Private Sub InitializePaging(ByVal ctlPagingControl As DotNetNuke.UI.WebControls.PagingControl, ByVal TotalRecords As Integer, ByVal PageSize As Integer)

            ctlPagingControl.TotalRecords = TotalRecords
            ctlPagingControl.PageSize = PageSize
            ctlPagingControl.CurrentPage = PageIndex

            Dim strQuerystring As String = ""
            'If ddlRecordsPerPage.SelectedIndex <> 0 Then
            '    strQuerystring += "&PageRecords=" + ddlRecordsPerPage.SelectedValue
            'End If
            'If intPortalID >= 0 Then
            '    strQuerystring += "&pid=" + intPortalID.ToString
            'End If
            'If strLogTypeKey <> "*" AndAlso strLogTypeKey <> "" Then
            '    strQuerystring += "&LogTypeKey=" + strLogTypeKey
            'End If
            ctlPagingControl.QuerystringParams = strQuerystring
            ctlPagingControl.TabID = TabId
        End Sub

        Protected Sub lstContent_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles lstContent.PageIndexChanged
            lstContent.CurrentPageIndex = e.NewPageIndex
        End Sub

        Protected Sub SortEventHandler(ByVal sender As Object, ByVal e As DataGridSortCommandEventArgs)
            '                Dim objComunicadorWebs As New ComunicadorWebController
            '                Dim colComunicadorWebs As List(Of ComunicadorWebInfo)
            '                ' Check to see if the column we clicked on is the current column defined 
            '                ' in the sortCriteria property.
            '                If Me.sortCriteria = e.SortExpression Then
            '                    If Me.sortDir = " desc" Then
            '                        Me.sortDir = " asc"
            '                    Else
            '                        Me.sortDir = " desc"
            '                    End If
            '                End If

            '                'strFilter = e.SortExpression
            '                Me.sortCriteria = e.SortExpression


            '                ' get the content from the ComunicadorWeb table
            '            colComunicadorWebs = objComunicadorWebs.GetComunicadorWebsSorted(PortalId, Me.UserInfo.UserID, Me.sortCriteria & " " & Me.sortDir)

            '                ' bind the content to the repeater
            '                lstContent.DataSource = colComunicadorWebs
            'lstContent.DataBind()

        End Sub

        'Public Property sortCriteria() As String
        '    Get
        '        Return CStr(viewstate("sortCriteria"))
        '    End Get
        '    Set(ByVal Value As String)
        '        ViewState("sortCriteria") = Value
        '    End Set
        'End Property
        '' Holds the direction to be sorted...
        'Public Property sortDir() As String
        '    Get
        '        Return CStr(viewstate("sortDir"))
        '    End Get
        '    Set(ByVal Value As String)
        '        ViewState("sortDir") = Value
        '    End Set
        'End Property

        Protected Sub NewPage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
            'Dim objComunicadorWebs As New ComunicadorWebController
            'Dim colComunicadorWebs As List(Of ComunicadorWebInfo)

            'lstContent.CurrentPageIndex = e.NewPageIndex
            '' get the content from the ComunicadorWeb table

            'If Me.sortCriteria = "" Then
            'colComunicadorWebs = objComunicadorWebs.GetComunicadorWebs(PortalId, Me.UserInfo.UserID)
            'else
            'colComunicadorWebs = objComunicadorWebs.GetComunicadorWebsSorted(PortalId, Me.UserInfo.UserID, Me.sortCriteria & " " & Me.sortDir)
            'End if

            '' bind the content to the repeater
            'lstContent.DataSource = colComunicadorWebs
            'lstContent.DataBind()

        End Sub
#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Registers the module actions required for interfacing with the portal framework
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection
                Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), False, Security.SecurityAccessLevel.Edit, True, False)
                Return Actions
            End Get
        End Property

#End Region

        Protected Sub LinkAgregarPeticion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkAgregarPeticion.Click
            Try
                Response.Redirect(NavigateURL(Me.TabId, "", "sgwcomunicador=AgregarPeticion"), True)
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Public Function getimgstatus(ByVal st As Integer) As String
            Dim ret As String
            Select Case st
                Case 1
                    ret = ModulePath & "images/img1.gif"
                Case Else
                    ret = ModulePath & "images/img2.gif"
            End Select
            Return ret
        End Function

    End Class

End Namespace
